package xyf.p11.other.prepoststatistics;

/**
 * ClassName: P0238_ProductExceptSelf
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:17 AM
 * Version: 1.0
 **/
public class P0238_ProductExceptSelf
{
    public int[] productExceptSelf(int[] nums)
    {
        int[] res = new int[nums.length];
        res[0] = 1;
        for (int i = 1; i < nums.length; i++)
        {
            res[i] = res[i - 1] * nums[i - 1];
        }

        int curR = 1;
        for (int j = nums.length - 1; j >= 0; j--)
        {
            res[j] = res[j] * curR;
            curR = curR * nums[j];
        }
        return res;
    }
}